package com.itheima.app.controller;

import cn.hutool.core.bean.BeanUtil;
import com.itheima.app.manager.QuestionNaireManager;
import com.itheima.domain.SoulTest.Answers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
public class QuestionNaireController {
    @Autowired
    private QuestionNaireManager questionNaireManager;

    @GetMapping("/testSoul")
    public ResponseEntity findTestSoul() {
        return questionNaireManager.findTestSoul();

    }

    @PostMapping ("/testSoul")
    public ResponseEntity submitQuestionnaire (@RequestBody Answers answers) {
//        System.out.println(answers);
        return questionNaireManager.submitQuestionnaire(answers);

    }
//第二种获得方法
//    @PostMapping("/testSoul")
//    public ResponseEntity submitQuestionnaire(@RequestBody Map map) {
//
//        List<Map> list = (List<Map>) map.get("answers");
//        List<Answers> answersList =new ArrayList<>();
//        for (Map map1 : list) {
//            String questionId = map1.get("questionId").toString();
//            String optionId = map1.get("optionId").toString();
//            Answers answers = new Answers();
//            answers.setOptionId(optionId);
//            answers.setQuestionId(questionId);
//            answersList.add(answers);
//        }
//        System.out.println("answersList"+answersList);
//
//        return null;
//    }

    @GetMapping("/testSoul/report/{id}")
    public ResponseEntity soulReport (@PathVariable String id) {
        System.out.println("report----"+id);
        return questionNaireManager.soulReport(id);

    }


}
